import CryptoJS from 'crypto-js'
export default {
    // 加密
    encrypt(word, keyStr, ivStr) {
        keyStr = keyStr ? keyStr : "kBab2e0KBA41e3cd";
        ivStr = ivStr ? ivStr : "54bef10750df41d5ac9f2d0a4fe100bf";
        let key = CryptoJS.enc.Utf8.parse(keyStr);
        let iv = CryptoJS.enc.Utf8.parse(ivStr);
        let srcs = CryptoJS.enc.Utf8.parse(word);

        let encrypted = CryptoJS.AES.encrypt(srcs, key, {
        iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.ZeroPadding
        });
        // return encrypted.toString();   //之前写法
        //以下为后修改的内容
        let aa=''
        aa = encrypted.replaceAll(System.lineSeparator(), ""); //将换行符替换为空
        return aa;
    },
    // 解密
    decrypt(word, keyStr, ivStr) {
        keyStr = keyStr ? keyStr : "kBab2e0KBA41e3cd";
        ivStr = ivStr ? ivStr : "54bef10750df41d5ac9f2d0a4fe100bf";
        var key = CryptoJS.enc.Utf8.parse(keyStr);
        let iv = CryptoJS.enc.Utf8.parse(ivStr);

        var decrypt = CryptoJS.AES.decrypt(word, key, {
        iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.ZeroPadding
        });
        return decrypt.toString(CryptoJS.enc.Utf8);
    }
}
